package com.api.shopapi.mapper;

import com.api.shopapi.entity.JKXuezhi;
import com.api.shopapi.entity.dto.JKXuezhiDTO;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
@Mapper
public interface JKXuezhiMapper {

    @Insert("insert into jk_xuezhi (JKXuezhiCode,UserCode,DanGuChun,GYSZhi,GMDDBai,DMDDBai,FromType,InspectTime,CreateTime) values " +
            "(#{jkXuezhi.JKXuezhiCode},#{jkXuezhi.UserCode},#{jkXuezhi.DanGuChun},#{jkXuezhi.GYSZhi},#{jkXuezhi.GMDDBai}," +
            "#{jkXuezhi.DMDDBai},#{jkXuezhi.FromType},#{jkXuezhi.InspectTime},#{jkXuezhi.CreateTime})")
    int insert(@Param("jkXuezhi") JKXuezhi jkXuezhi);

    @Update("update jk_xuezhi set UserCode=#{jkXuezhi.UserCode},DanGuChun=#{jkXuezhi.DanGuChun},GYSZhi=#{jkXuezhi.GYSZhi},GMDDBai=#{jkXuezhi.GMDDBai}," +
            "DMDDBai=#{jkXuezhi.DMDDBai},FromType=#{jkXuezhi.FromType},InspectTime=#{jkXuezhi.InspectTime},CreateTime=#{jkXuezhi.CreateTime} " +
            "where JKXuezhiCode=#{jkXuezhi.JKXuezhiCode}")
    int update(@Param("jkXuezhi") JKXuezhi jkXuezhi);

    @Delete("delete from jk_xuezhi where JKXuezhiCode=#{jKXuezhiCode}")
    int delete(@Param("jKXuezhiCode") String jKXuezhiCode);

    @Select("select * from jk_xuezhi where JKXuezhiCode=#{jKXuezhiCode} limit 1")
    JKXuezhi getByJKXuezhiCode(@Param("jKXuezhiCode") String jKXuezhiCode);

    @Select("select * from jk_xuezhi where UserCode=#{userCode} and InspectTime between #{startTime} and #{endTime} order by InspectTime desc")
    List<JKXuezhi> getPageList(@Param("userCode") String userCode,@Param("startTime") String startTime,@Param("endTime") String endTime);


    @Select("<script>" +
            "select jx.*,u.Name as userName from jk_xuezhi jx left join user u on jx.UserCode=u.UserCode " +
            "where u.GovernmentCode=#{governmentCode} " +
            "<if test ='name !=null and name!=\"\" '>" +
            "and u.Name like concat('%',#{name},'%') " +
            "</if>" +
            "and jx.InspectTime between #{startTime} and #{endTime} " +
            "order by jx.InspectTime desc" +
            "</script>")
    List<JKXuezhiDTO> getAdmPageList(@Param("name") String name, @Param("governmentCode") String governmentCode, @Param("startTime") String startTime, @Param("endTime") String endTime);

}
